package com.huobao.shangjia_version.activitys;

import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.entity.Renzheng_Geren_Detail;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.zhangying.R;

import org.xutils.view.annotation.ViewInject;

import java.util.Map;

/**
 * Created by Administrator on 2016/8/19.
 */
public class Act_See_Geren_Renzheng extends HuobaoBaseActivity{
	//账户名
	@ViewInject(R.id.tv_zhanghu)
	private TextView tv_zhanghu;
	//店铺名称
	@ViewInject(R.id.tv_storename)
	private TextView tv_storename;
	//真实姓名
	@ViewInject(R.id.tv_truename)
	private TextView tv_truename;
	//身份证号
	@ViewInject(R.id.tv_id_num)
	private TextView tv_id_num;
	//身份证到期时间
	@ViewInject(R.id.tv_endtime)
	private TextView tv_endtime;
	//开户银行
	@ViewInject(R.id.tv_bank)
	private TextView tv_bank;
	//开户银行所在地
	@ViewInject(R.id.tv_bankaddress)
	private TextView tv_bankaddress;
	//银行账号
	@ViewInject(R.id.tv_id_bank)
	private TextView tv_id_bank;
	//身份证正面
	@ViewInject(R.id.iv_zhengmian)
	private ImageView iv_zhengmian;
	//身份证反面
	@ViewInject(R.id.iv_fanmian)
	private ImageView iv_fanmian;

	@Override
	protected int getContentView() {
		return R.layout.layout_see_geren_renzheng;
	}

	@Override
	protected String getTitleText() {
		return "个人认证详情";
	}

	@Override
	protected void init() {
		getUserMember();
		getDetail();
	}

	private void getDetail() {
		Map<String, String> map = HttpUtil.getParams("app", "approve", "act", "view");
		Http.getInstant().sendRequest(context, map, new HttpListener() {
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				Renzheng_Geren_Detail detail = JSON.parseObject(jsonObject.getString("retval"), Renzheng_Geren_Detail.class);
				showDetail(detail);
			}

			@Override
			public void onHttpError(String error) {

			}
		});
	}
	private void showDetail(Renzheng_Geren_Detail detail) {
		tv_id_num.setText(detail.getNumber_id());
		tv_truename.setText(detail.getUser_name());
		tv_id_bank.setText(detail.getBank_account());
		tv_endtime.setText(detail.getLong_time().equals("1") ? "长期" : detail.getEndtimeNum());
		tv_bank.setText(detail.getBank_text());
		tv_bankaddress.setText(detail.getRegion_name());
		ImageUtils.loadimg(iv_zhengmian, detail.getIdnumber_facade());
		ImageUtils.loadimg(iv_fanmian, detail.getIdnumber_obverse());
	}

	private void getUserMember() {
		Map<String, String> map = HttpUtil.getParams("app", "approve", "act", "member");
		Http.getInstant().sendRequest(context, map, new HttpListener() {
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				jsonObject = jsonObject.getJSONObject("retval");
				String user_name = jsonObject.getString("user_name");
				String shop_name = jsonObject.getString("shop_name");
				tv_zhanghu.setText(user_name);
				tv_storename.setText(shop_name);
			}

			@Override
			public void onHttpError(String error) {

			}
		});
	}
}
